/*
 * @lc app=leetcode.cn id=1984 lang=typescript
 *
 * [1984] 学生分数的最小差值
 */

// @lc code=start
function minimumDifference(nums: number[], k: number): number {
    if (nums.length === 1) return 0;
    nums.sort((a, b) => a - b);
    let min = Infinity;
    k = k - 1;
    for (let i = k; i < nums.length; i++) {
        const prev = nums[i - k];
        const element = nums[i];
        min = Math.min(element - prev, min);
    }
    return min;
}
// @lc code=end
